home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6753 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.9 KB  |  124 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!milyng
  3. From: jerry@graveyard.com (Jerry Garcia)
  4. Subject: Re: Linking LIBs (file dependencies)
  5. Message-ID: <milyngDMnGox.8vL@netcom.com>
  6. Sender: milyng@netcom15.netcom.com
  7. Organization: Ghost Communications, Inc.
  8. X-Newsreader: WinVN 0.99.7
  9. References: <4ee2ta$6b3@masala.cc.uh.edu> <milyngDM8In2.KLu@netcom.com> <4f3fnq$snd@masala.cc.uh.edu>
  10. Date: Mon, 12 Feb 1996 06:29:21 GMT
  11.  
  12. In article <4f3fnq$snd@masala.cc.uh.edu>, txs53132@bayou.uh.edu says...
  13.  
  14. >Thanks.  That problem dissapeared (and I didn't even do anything!).  
  15.  
  16. I wish all problems were that simple :)
  17.  
  18. >I have a new problem now, but I think I found a solution.  My program (a 
  19. >dragon game) runs fine, but crashes randomly when the program exits.  I 
  20. >run it, it crashes, I reset the computer, I run it again, and it works 
  21. >fine!  I tried doing a COMPILE/BUILD ALL before running and it hasn't 
  22. >crashed for a while.  Does that option have anything to do with module 
  23. >structurization?
  24.  
  25. Hmm...  It sounds like your problem is that things get out of sync - that
  26. not all required files are rebuilt properly when you make a change somewhere.  
  27.  
  28. If that's the case, which it commonly is when you experience spurious errors 
  29. that disappear after a complete rebuild, you need to do one of the following:  
  30. 1) Use the brute force method - always do a complete rebuild.  2) Ensure your 
  31. source file dependencies are correct.  I.e., somewhere, somehow you specify 
  32. the dependencies between modules in your IDE (I assume you're using an IDE 
  33. because of your reference to COMPILE/BUILD ALL) and somehow these dependencies 
  34. aren't up to date.  How to manage dependencies depends (pun intended) 
  35. extremely much on exactly how you build your application.  If you're using a  
  36. make utility, you pretty much have to keep them up to date yourself.  If 
  37. you're using MSVC, I think it does most (if not all) of the work for you.  As 
  38. for Borland (that's the one you're using?  I don't recall COMPILE/BUILD ALL in 
  39. any other IDE), I think you have to do it manually in the IDE somehow.  I will 
  40. here describe what you need to do get your dependencies up to date manually - 
  41. this method works for both makefiles and for Borland's IDE.  
  42.  
  43. In make/build terms, file A depends upon file B if file A needs to be 
  44. recompiled/remade/rebuilt/regenerated/whatever whenever file B is changed.  
  45. The most obvious type of dependency is that the dependency between an object 
  46. file and the source file used to generate the object file.  In virtually all 
  47. cases where the source file has been changed, the object file needs to be 
  48. rebuilt (by compiling the source file).  In a makefile this is typically 
  49. expressed as:
  50.  
  51.     filename.obj: filename.c
  52.  
  53. However, this is the most simple type of dependency.  I guess you can call it 
  54. a "source dependency".  The one that causes most problems are "usage 
  55. dependencies" - where one file uses another without causing a new file to be 
  56. created.  A good example of this is a C source file's use of a header file.  
  57. If the header file changes, the object file created from the C source file 
  58. should be updated - even though the C source file hasn't been changed.  In a 
  59. makefile, this can be expressed in two ways:
  60.  
  61.     filename.obj: filename.c header.h
  62.  
  63. Or more correctly:
  64.  
  65.     filename.obj: filename.c
  66.  
  67.     filename.c  : header.h
  68.  
  69. (I consider this "more correct' because it means "filename.obj depends upon 
  70. filename.c.  filename.c depends upon header.h" (vs. "filename.obj depends upon 
  71. filename.c and header.h").
  72.  
  73. Anyway, from here on things are pretty simple.  Just as a C source file can 
  74. depend upon a header file (by including it), a header file can also depend 
  75. upon another header file (by including it).  And so forth - a library depends 
  76. upon the object files in the library who again depends upon the source files 
  77. used to create them who again depends upon the header files they include.
  78.  
  79. So, you pretty much just need to go through all of your source files and 
  80. determine what header files they depend upon.  After that, you go through all 
  81. your header files and determine what header files they depend upon.  When you 
  82. have all this information, you can pass it on to your build tool - whether a 
  83. make utility or an IDE of some sort.  
  84.  
  85. A few notes:  
  86.  
  87. 1. Outdated dependency information is usually worth less than no dependency 
  88. information (because outdated dependency information frequently causes 
  89. programs to be built on outdated assumptions, whereas no dependency 
  90. information usually requires the program to be completely rebuilt - which is 
  91. tedious, but gives the proper result).  
  92.  
  93. 2. When you "map" dependency information, you rarely need to include 
  94. "standard" headers (such as the ANSI C library headers and 3rd party library 
  95. headers).  These headers change so infrequently that it doesn't seem very 
  96. useful to keep checking if they have changed.  You just need to remember to do 
  97. a complete rebuild whenever you update your compiler etc (which shouldn't be 
  98. that hard).  A good way to distinguish between standard, or global, headers 
  99. and project-specific, or local, headers, is to use the #include statement 
  100. itself to distinguish:
  101.  
  102. #include <global.h>    /* angle braces indicate global header */
  103.  
  104. #include "local.h"     /* quotes indicate local header */
  105.  
  106. As a matter of fact, most dependency mapping tools support this directly.  
  107. They won't include information about header files listed in angle braces (and 
  108. won't scan them for dependencies either), but will include the headers listed 
  109. in quotes.  
  110.  
  111. 3. Consider to use a make-like notation (as in the example above).  If you 
  112. keep doing this, you will someday find yourself wanting to use a real make 
  113. utility (and be able to do it easily).  The primary advantage of this, is that 
  114. you free yourself of vendor-dependencies and will make life much easier for 
  115. yourself, if you someday decide to switch to another compiler or you need to 
  116. port your app to another platform. 
  117.  
  118. Hope this is of some help to you.  Sorry if it is wildly off track, but I kind 
  119. of got caught up in explaining this :)
  120.  
  121.  
  122. Mikael
  123.  
  124.